package de.openkanban.client.ui.presenter;

import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.Response;
import com.smartgwt.client.util.SC;

import de.openkanban.client.ui.board.ActivityView;
import de.openkanban.shared.dto.ActivityDto;

/**
 * Callback that handles get activity by id request
 */
public class GetActivityByIdRequestCallback implements RequestCallback {

	private ActivityView activityView;
	
	public GetActivityByIdRequestCallback(ActivityView activityView) {
		super();
		this.activityView = activityView;
	}

	@Override
	public void onResponseReceived(Request request, Response response) {
		ActivityDto activityDto = new ActivityDto(response.getText());
		if (response.getStatusCode() < 300 && activityDto.isCallSuccessfull()) {
			activityView.setActivityDto(activityDto);
		} else {
			SC.say("Fehler: " + response.getStatusText());
		}		
	}

	@Override
	public void onError(Request request, Throwable exception) {
	}

}
